pip3 install gunicorn django"==1.11" numpy python-daemon pyscada pyvisa pyvisa-py pyownet 
#pip3 install smbus-cffi 网络卡死
apt-get install -y python3-pip libhdf5-100 libhdf5-dev python3-dev nginx owfs libffi-dev
mkdir -p /var/www
useradd -r pyscada
mkdir -p /var/www/pyscada/http
chown -R pyscada:pyscada /var/www/pyscada
mkdir -p /home/pyscada
chown -R pyscada:pyscada /home/pyscada

cd /var/www/pyscada/
sudo -u pyscada django-admin startproject PyScadaServer

cd PyScadaServer/

sudo wget https://gitee.com/kaikong/oscmd/raw/master/ubuntu/var/www/pyscada/PyScadaServer/PyScadaServer/urls.py -O /var/www/pyscada/PyScadaServer/PyScadaServer/urls.py
#nano PyScadaServer/urls.py
#from django.conf.urls import url, include
#from django.contrib import admin
#urlpatterns = [
#    url(r'^admin/', admin.site.urls),
#    url(r'^', include('pyscada.hmi.urls')),
#]

sudo wget https://gitee.com/kaikong/oscmd/raw/master/ubuntu/var/www/pyscada/PyScadaServer/PyScadaServer/settings.py -O /var/www/pyscada/PyScadaServer/PyScadaServer/settings.py
#nano PyScadaServer/settings.py

sudo -u pyscada python3 manage.py migrate
sudo -u pyscada python3 manage.py collectstatic
sudo -u pyscada python3 manage.py loaddata color
sudo -u pyscada python3 manage.py loaddata units
sudo -u pyscada python3 manage.py pyscada_daemon init

sudo -u pyscada python3 manage.py createsuperuser
sudo wget https://raw.githubusercontent.com/trombastic/PyScada/dev/0.7.x/extras/nginx_sample.conf -O /etc/nginx/sites-available/pyscada.conf
sudo wget https://raw.githubusercontent.com/trombastic/PyScada/dev/0.7.x/extras/service/systemd/gunicorn.socket -O /etc/systemd/system/gunicorn.socket
sudo wget https://raw.githubusercontent.com/trombastic/PyScada/dev/0.7.x/extras/service/systemd/gunicorn.service -O /etc/systemd/system/gunicorn.service
sudo wget https://raw.githubusercontent.com/trombastic/PyScada/dev/0.7.x/extras/service/systemd/pyscada_daemon.service -O /etc/systemd/system/pyscada.service

sudo mkdir /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 1780 -newkey rsa:2048 -keyout /etc/nginx/ssl/pyscada_server.key -out /etc/nginx/ssl/pyscada_server.crt

sudo ln -s /etc/nginx/sites-available/pyscada.conf /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl enable nginx.service
sudo systemctl restart nginx
# in some installations gunicorn is not at /usr/local/bin/gunicorn but at /usr/bin/gunicorn
# in this case you have to change the pat in the file /etc/systemd/system/gunicorn.service accordingly

# enable the services for autostart
sudo systemctl enable gunicorn
sudo systemctl start gunicorn
sudo systemctl enable pyscada
sudo systemctl start pyscada

#以下不用
python3 ./manage.py runserver --insecure
python3 ./manage.py PyScadaWindowsDaemonHandler daemon_name
register_windows_service_modbus.py